package com.xm_jd.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xm_jd.model.dao.ZcDao;
import com.xm_jd.model.entitys.user;
import com.xm_jd.utils.BaseServlet;

/**
 * Servlet implementation class regist
 */
@WebServlet("/regist")
public class regist extends BaseServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public regist() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		
		//获取用户名
		String uname = request.getParameter("uname");

		if (uname != null) {
			// 调用查询账号是否存在的方法
			List<user> list = new ZcDao().Selectname(uname);
			if (list.size() > 0) {
				response.getWriter().print(1);
			} else if(!(list.size()>0)) {
				response.getWriter().print(2);
			}
		}else{
			response.getWriter().print(3);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
